<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>用户登录</title>
  <script src="js/vue.min.js"></script>
  <script src="js/jquery-1.12.4.js"></script>
</head>

<body>
  <div id="app">
    <form action="#">
      帐号：<input type="text" name="uname" v-model="username" /><br />
      密码：<input type="text" name="upass" v-model="password" /><br />
      <div v-if="isLoginErr" style="color:red">错误的帐号或密码</div>
      <button type="button" @click="login">登录</button>
    </form>
  </div>

  <script>
    new Vue({
      el: "#app",
      data: {
        username: 'zing',
        password: '123',
        isLoginErr: false
      },
      methods: {
        login() {

          let that = this;

          let params = {
            'username': this.username,
            'password': this.password
          }

          $.ajax('http://localhost:8080/jwt/api/login', {
            type: 'post',
            data: params,
            dataType: 'json',
            success: function (res) {
              if (res.code == 200) {
                localStorage.setItem("token", res.data);
                location.href = "main.html"
                return;
              }
              that.isLoginErr = true;
            }
          });
        }
      }

    });
  </script>


</body>

</html>